<template>
  <div class="out">
    <!-- 头部区域 -->
    <header class="header">
      <!-- 头部的第一行 -->
      <div class="top">
        <div class="typeList">
          <router-link to="/AboutMe" class="singleList">关于本站</router-link>
          <router-link to="/MyPapers" class="singleList">我的文章</router-link>
          <router-link to="/MyComments" class="singleList"
            >我的留言</router-link
          >
          <router-link to="/MyPic" class="singleList">我的相册</router-link>
          <router-link to="/MyMemo" class="singleList">我的备忘录</router-link>
          <router-link to="/login" class="singleList" @click.native="loginAdmin"
            >后台登录</router-link
          >
        </div>
      </div>
    </header>
    <!--logo区域-->
    <div class="bottom" v-show="login">
      <!-- router-link组件本省就是一个a标签 -->
      <router-link to="/" class="zhm_logo"> 敏宝小窝! </router-link>
    </div>
    <!-- 换肤 -->
    <div class="changeBgc" v-show="login">
      <button class="button" @click="changeShowBg" v-model="isShowBg">
        {{ isShowBg }}
      </button>
      <button class="button second" @click="recover" v-show="hideBg">
        恢复默认背景样式
      </button>
      <ul v-show="hideBg">
        <li v-for="item in bgImages" @click="changeBgI">
          <img :src="item.bgUrl" />
        </li>
      </ul>
      <div class="upLoad">
        <!-- 开发好再解开这个库，不然一直报错 -->
        <!-- <el-upload
          action="https://jsonplaceholder.typicode.com/posts/"
          list-type="picture-card"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove"
        >
          <i class="el-icon-plus">上传新的背景图</i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="" />
        </el-dialog> -->
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "",
  props: ["userName"], //接收父组件传递过来的数据
  data() {
    return {
      login: true, //logo标签是否显示
      isShowBg: "展示背景选项", //是否展示背景图片
      hideBg: false,
    };
  },
  mounted() {
    // 发请求获取所有背景图片
    this.$store.dispatch("getBgImages");
  },
  methods: {
    // 用户点击登录后台系统，给父组件App传递数据，不展示Header
    loginAdmin() {
      this.login = false;
      // 向父组件传递数据
      this.$bus.$emit("isShowHeader", this.login);
    },
    // 用户点击更换背景
    changeBgI(e) {
      var target = e.target; //点击的目标元素
      var src = target.src;
      document.body.style.backgroundImage = "url(" + src + ")";
    },
    // 用户点击恢复默认样式
    recover() {
      document.body.style.background =
        "linear-gradient(to right, rgb(192, 214, 233), rgb(161, 142, 230))";
    },
    // 当用户点击隐藏显示背景按钮
    changeShowBg(e) {
      console.log(e.target);
      this.hideBg = !this.hideBg;
      if (this.hideBg) this.isShowBg = "隐藏背景选项";
      else this.isShowBg = "展示背景选项";
    },
  },
  computed: {
    ...mapState({
      bgImages: (state) => state.bgImages.bgImages,
    }),
  },
};
</script>

<style  lang="less">
.header {
  background-color: rgba(250, 242, 252, 0.5);
  overflow: hidden;
  .top {
    height: 20px;
    line-height: 20px;
    font-size: 18px;
    .loginList {
      float: left;
      margin-left: 120px;
      .register {
        border-left: 1px solid #b3aeae;
        padding: 0 5px;
        margin-left: 5px;
      }
      .register:hover,
      span:hover {
        border-radius: 15px;
        background-color: rgb(161, 142, 247);
      }
    }
    .typeList {
      float: right;
      margin-right: 50px;
      margin-top: 16px;
      a {
        text-decoration: none;
      }
      .singleList {
        border-right: 1px solid #b3aeae;
        padding: 0 5px;
        margin-right: 5px;
      }
      // 取消最后一个孩子的右边框
      .singleList:last-child {
        border-right: 0;
      }
      .singleList:hover {
        border-radius: 15px;
        background-color: rgb(161, 142, 247);
      }
    }
  }
}
.bottom {
  background-color: rgba(135, 206, 235, 0.3);
  padding-top: 15px;
  padding-left: 45px;
  opacity: 0.6;
  .zhm_logo {
    font-size: 40px;
    font-weight: bold;
    font-family: STXingkai;
    text-decoration: none;
    background-image: -webkit-linear-gradient(right, #e95e1e, #4876f5, #0b9fb9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
.isShow {
  position: absolute;
  left: 70px;
  top: 180px;
  width: 120px;
  height: 40px;
  line-height: 40px;
  display: flex;
  justify-content: center;
  background-color: #ade2f7;
  opacity: 0.7;
  border-radius: 15px;
}
.changeBgc {
  position: relative;
  display: flex;
  .button {
    position: absolute;
    font-size: 18px;
    margin-top: 15px;
    margin-left: 50px;
    font-family: serif;
    width: 160px;
    height: 25px;
    line-height: 25px;
    border: none;
    border-radius: 10px;
    // 设置盒子的文字居中显示
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(173, 226, 247, 0.6);
  }
  .second {
    margin-top: 50px;
  }
  ul {
    // position: absolute;
    list-style-type: none;
    display: inline;
    width: 900px;
    margin-left: 200px;
    li {
      list-style-type: none;
      float: left;
      margin: 0 1px;
      cursor: pointer;
      img {
        width: 100px;
        height: 60px;
      }
    }
  }
  p:first-child {
    background-color: #ade2f7;
    opacity: 0.7;
    margin-left: 50px;
    // margin-right: -10px;
  }
  .upLoad {
    p {
      font-size: 18px;
      font-family: serif;
      display: inline-block;
      width: 160px;
      height: 40px;
      line-height: 40px;
      background-color: #e5c9f8;
      opacity: 0.7;
      // 设置盒子的文字居中显示
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .el-upload--picture-card {
      background-color: rgba(255, 255, 255, 0.3);
      width: 160px;
      height: 40px;
      position: absolute;
      margin-left: -55px;
      margin-top: 10px;
      // 设置盒子的文字居中显示
      display: flex;
      justify-content: center;
      align-items: center;
      .el-icon-plus {
        font-size: 14px;
      }
    }
  }
}
</style>
